<template>
	<view class='product-action bg-color-pageBg'>
		<view class="button flex-center-sb">
			<w-button type="colorful" shape="circle" disabled v-if="!info.user_hash" style="flex: 1;">{{handleLang('上链中')}}</w-button>
			<block v-else>
				<!-- status 1持有 2寄售 -->
				<!-- can_compose 可合成； is_lock 锁单 -->
				<w-button type="colorful" shape="circle" disabled v-if="info.status == 10" style="flex: 1;">{{handleLang('赠送中')}}</w-button>
				<w-button type="colorful" shape="circle" disabled v-if="info.status==2 && info.product.is_lock==1" style="flex: 1;">{{handleLang('锁定中')}}</w-button>
				<w-button type="colorful" shape="circle" v-if="info.product.weither_regift==0 && info.status==1" style="flex: 1;" @click='regift'>{{handleLang('转赠')}}</w-button>
				<!-- <w-button type="colorful" shape="circle" v-if="info.product.can_compose==1 && !info.product.is_lock==1 && info.status==1" style="flex: 1;" @click="goCompound">{{handleLang('合成')}}</w-button> -->
				<view class="flex flex-ai-center w-100" v-if="info.product.weither_resale==0 && info.status==1">
					<view @click="toMarket" class="flex flex-ai-center mr-12">
						<view class="font-color-white font-size-16 font-w-600" style="color: #1E1E1E;">市场列表</view>
						<w-icon name="right" size="20"></w-icon>
					</view>
					<w-button type="colorful" shape="circle"  style="flex: 1;" @click="consignment">{{handleLang('立即寄售')}}</w-button>
				</view>
				
				
				<w-button type="colorful" shape="circle" v-if="info.status==2 && info.product.is_lock!=1" style="flex: 1;" @click="cancel_consignment_pop=true">{{handleLang('取消寄售')}}</w-button>
				<w-button type="colorful" shape="circle" disabled
				v-if="info.status==1 && info.product.is_lock!=1 && info.product.weither_regift==1 && info.product.weither_resale==1 && info.product.can_compose==0" style="flex: 1;">{{handleLang('尚未开启寄售')}}</w-button>
			</block>
		</view>
		<w-toast v-model="cancel_consignment_pop" contentAlign="center" :content="handleLang('确认取消此寄售？')" @action='cancelConsignment'></w-toast>
	</view>
</template>

<script>
	import { mapActions } from 'vuex';
	import { changeMarketGoods } from '@/api/market/index.js';
	export default {
		props:{
			info:{
				type: Object
			},
			goodsType:{
				type: [Number,String],
				default: 2
			}
		},
		data() {
			return {
				cancel_consignment_pop:false
			};
		},
		methods:{
			...mapActions('config',['getPageConfig']),
			// 立即寄售
			consignment() {
				uni.$u.route('/pages/consignments/consignments',{id:this.info.id,pageType:2})
			},
			toMarket(){
				uni.navigateTo({
					url:`/pages/market/marketGoodsList?id=${this.info.collection_id}&goodsType=${this.goodsType}`
				})
			},
			regift(){
				uni.$u.route('/pages/regift/regift',{id:this.info.id})
			},
			
			// 取消寄售
			cancelConsignment(e) {
				if(!e) return
				uni.showLoading()
				changeMarketGoods({ id:this.info.market_goods.id }).then(()=>{
					this.$emit('refresh')
				}).catch(()=>{})
			},
			
			// 去合成
			goCompound() {
				uni.showLoading({
					mask:true
				})
				this.getPageConfig().then(res=>{
					try{
						let arry = res.find(v => v.type == 'menu' && v.category == 'home').content.list
						let path = arry.find(item=>item.name=='合成通道').path
						uni.$u.route(path)
					}catch(e){
						console.log(e)
						uni.$u.toast('合成未开启');
					}
				}).catch(()=>{  })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.product-action {
		width: 750rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 999;
		padding-bottom: env(safe-area-inset-bottom);
		>.button{
			padding: 12rpx 32rpx;
			gap: 32rpx;
		}
	}
	.btn_style{
		
	}
</style>
